package com.macro.mall.portal.controller;

import com.macro.mall.common.api.CommonResult;
import com.macro.mall.model.BmsSightseeingBus;
import com.macro.mall.model.BmsSightseeingBusApplicant;
import com.macro.mall.model.BmsSightseeingBusPoint;
import com.macro.mall.portal.dto.BmsSightseeingBusParam;
import com.macro.mall.portal.service.BmsSightseeingBusApplicantService;
import com.macro.mall.portal.service.BmsSightseeingBusService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 小程序观光车预约Controller
 * Created by macro on 2018/4/26.
 */
@Controller
@Api(tags = "BmsSightseeingBusApplicantController")
@Tag(name = "BmsSightseeingBusApplicantController", description = "观光车管理")
@RequestMapping("/mpListXiao")
public class BmsSightseeingBusApplicantController {
    @Autowired
    private BmsSightseeingBusApplicantService bmsSightseeingBusApplicantService;
    @Autowired
    private BmsSightseeingBusService bmsSightseeingBusService;


    /**
     *
     * 查询观光车列表
     * @return
     */
    @ApiOperation("小程序查询观光车")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<List<BmsSightseeingBus>> getMpList() {
        List<BmsSightseeingBus> bmsSightseeingBusList = bmsSightseeingBusService.getMpList();
        return CommonResult.success(bmsSightseeingBusList);
    }

    /**
     * 查询观光车点位
     * @return
     */
    @ApiOperation("小程序查询观光车选择点位信息")
    @RequestMapping(value = "/point", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<List<BmsSightseeingBusPoint>> getMpListPoint(@RequestBody BmsSightseeingBusPoint bmsSightseeingBusPoint) {
        List<BmsSightseeingBusPoint> bmsSightseeingBusPointList = bmsSightseeingBusApplicantService.getMpListPoint(bmsSightseeingBusPoint);
        return CommonResult.success(bmsSightseeingBusPointList);
    }

    /**
     *
     * 查询观光车详情
     * @return
     */
    @ApiOperation("小程序查询观光车")
    @RequestMapping(value = "/getBusDetail", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<BmsSightseeingBus> getBusDetail(@RequestBody BmsSightseeingBus bmsSightseeingBus) {
        BmsSightseeingBus result = bmsSightseeingBusService.getBusDetail(bmsSightseeingBus);
        return CommonResult.success(result);
    }


    @ApiOperation("添加观光车预约记录")
    @RequestMapping(value = "/create", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<?> create(@RequestBody BmsSightseeingBusApplicant bmsSightseeingBusApplicant){
        try {
            BmsSightseeingBusApplicant bmsSightseeingBusApplicant1 = bmsSightseeingBusApplicantService.create(bmsSightseeingBusApplicant);
            return CommonResult.success(bmsSightseeingBusApplicant1);
        }catch (Exception e){
            return CommonResult.failed("您已成功预约该辆观光车,无需再次预约！");
        }
    }


    @ApiOperation("修改观光车预约记录")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<?> update(@RequestBody BmsSightseeingBusApplicant bmsSightseeingBusApplicant) {
        bmsSightseeingBusApplicantService.update(bmsSightseeingBusApplicant);
        return CommonResult.success();
    }




    @ApiOperation("小程序查询观光车详情")
    @RequestMapping(value = "/detail", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<List<BmsSightseeingBusApplicant>> getMpListDetail(@RequestBody BmsSightseeingBusParam bmsSightseeingBusParam) {
        List<BmsSightseeingBusApplicant> bmsSightseeingBusList = bmsSightseeingBusService.getMpDetail(bmsSightseeingBusParam);
        return CommonResult.success(bmsSightseeingBusList);
    }


    @ApiOperation("小程序查询观光车是否报名成功详情页面")
    @RequestMapping(value = "/getListByUserId", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<?> getListByUserId() {
        List<BmsSightseeingBusApplicant> bmsSightseeingBusApplicant = bmsSightseeingBusApplicantService.getListByUserId();
        return CommonResult.success(bmsSightseeingBusApplicant);
    }

    @ApiOperation("小程序查询观光车是否报名成功详情页面")
    @RequestMapping(value = "/getSuccessBusDataByUserId", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<?> getSuccessBusDataByUserId(@RequestBody BmsSightseeingBusApplicant bmsSightseeingBusApplicant) {
        BmsSightseeingBusApplicant result = bmsSightseeingBusApplicantService.getSuccessBusDataByUserId(bmsSightseeingBusApplicant);
        return CommonResult.success(result);
    }

    @ApiOperation("获取当前用户预约车辆数量")
    @RequestMapping(value = "/getCountByUserId", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<?> getCountByUserId() {
        List<BmsSightseeingBusApplicant> bmsSightseeingBusApplicant = bmsSightseeingBusApplicantService.getListByUserId();
        return CommonResult.success(bmsSightseeingBusApplicant.size());
    }
}
